package com.vanke.devops.domain.manager.docker.bean;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * @author 陈景阳
 * @since 2018/6/5
 */
@Getter
@Setter
public class Memory{

    private Double usage;
    @JsonProperty("max_usage")
    private Double maxUsage;
    private Double limit;
    private Stats stats;
    
    private Double toGb(Double value){
        //这里的*10有点不知道为啥，但是数据是对的
        return value / (1024 * 1024) * 10 / 1024;
    }

    public Double getUsagePercent() {
        Double limit = toGb(getLimit());
        Double usage = toGb(getUsage());
        return usage / limit;
    }

    @Getter
    @Setter
    //TODO 没有下划线转驼峰
    public class Stats{
        private Double activeAnon;
        private Double activeFile;
        private Double cache;
        private Double hierarchicalMemoryLimit;
        private Double hierarchicalMemswLimit;
        private Double inactiveAnon;
        private Double inactiveFile;
        private Double mappedFile;
        private Double pgfault;
        private Double pgmajfault;
        private Double pgpgin;
        private Double pgpgout;
        private Double rss;
        private Double rssHuge;
        private Double swap;
        private Double totalActiveAnon;
        private Double totalActiveFile;
        private Double totalCache;
        private Double totalInactiveAnon;
        private Double totalInactiveFile;
        private Double totalMappedFile;
        private Double totalPgfault;
        private Double totalPgmajfault;
        private Double totalPgpgin;
        private Double totalPgpgout;
        private Double totalRss;
        private Double totalRssHuge;
        private Double totalSwap;
        private Double totalUnevictable;
        private Double unevictable;
    }
}
